import java.io.*;
import java.util.ArrayList;
import java.util.Collections;

/**
 * Created by IntelliJ IDEA.
 * User: mirouhh
 * Date: 07.10.2008
 * Time: 15:29:14
 * Web: http://jughh.org
 * Blog: http://datacrunching.blogable.org
 */
public class DataCruncher {

    public static void main(String[] args) {
        try{
            BufferedReader bufferedReader = new BufferedReader(new FileReader(new File("../sample.txt")));
            String line;
            ArrayList<String> content = new ArrayList();

            // reading file content
            while((line = bufferedReader.readLine()) != null) {                                   
                content.add(line);
            }
            bufferedReader.close();

            // reversing content
            Collections.reverse(content);

            // writing content
            BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("../result.txt"));
            for (String aLine : content) {
                bufferedWriter.write(aLine + "");
            }
            bufferedWriter.flush();
            bufferedWriter.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}